#include "max6675_drv.h"

typedef struct {
	reg32* csON;
	reg32* csOFF;
	int pin;
} tPort;

static tPort port[MAX6675_N_SENSORS];

void max6675_SetupPorts(void) {
	port[0].csOFF = &MAX6675_CS0_OFF;
	port[0].csON = &MAX6675_CS0_ON;
	port[0].pin = MAX6675_CS0;
	MAX6675_CS0_DIR |=  MAX6675_CS0;

	#if (MAX6675_N_SENSORS > 1)
	port[1].csOFF = &MAX6675_CS1_OFF;
	port[1].csON = &MAX6675_CS1_ON;
	port[1].pin = MAX6675_CS1;
	MAX6675_CS1_DIR |=  MAX6675_CS1;
	#endif

	#if (MAX6675_N_SENSORS > 2)
	port[2].csOFF = &MAX6675_CS2_OFF;
	port[2].csON = &MAX6675_CS2_ON;
	port[2].pin = MAX6675_CS2;
	MAX6675_CS2_DIR |=  MAX6675_CS2;
	#endif

	#if (MAX6675_N_SENSORS > MAX6675_MAX_N_SENSORS)
	#error O LIMITE DE GERENCIAMENTO DOS SENSORES MAX6675 FOI SUPERADO. ver _config_lib_sensor.h
	#endif
}

int max6675_Enable(int dev) {
	if (dev > MAX6675_N_SENSORS-1) return pdFALSE;
	*port[dev].csON = port[dev].pin;
	return pdPASS;
}

int max6675_Disable(int dev) {
	if (dev > MAX6675_N_SENSORS-1) return pdFALSE;
	*port[dev].csOFF = port[dev].pin;
	return pdPASS;
}

